package com.coderush.admin.sys.dao;

import com.coderush.admin.sys.mapper.RoleMenuMapper;
import com.coderush.admin.sys.model.dto.MenuAssignDto;
import com.coderush.admin.sys.model.entity.RoleMenu;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * PackageName com.coderush.admin.sys.dao
 *
 * @Author Eason
 * @Version v1.0
 * @ClassName RoleMenuDao
 * @Date 2025/8/29
 * @Description TODO
 */
@Repository
public class RoleMenuDao {

    @Resource
    private RoleMenuMapper roleMenuMapper;

    /**
     * 添加角色菜单关系
     */
    public Boolean add(RoleMenu roleMenu) {
        return roleMenuMapper.insert(roleMenu) > 0;
    }

    /**
     * 根据角色id查询菜单id
     */
    public List<Long> findByRoleIds(List<Long> roleIds) {
        return roleMenuMapper.findByRoleIds(roleIds);
    }

    /**
     * 根据角色id删除角色菜单关系
     */
    public void deleteByRoleId(Long roleId) {
        roleMenuMapper.deleteByRoleId(roleId);
    }

    public void doAssign(MenuAssignDto menuAssignDto) {
        roleMenuMapper.doAssign(menuAssignDto);
    }
}